{extend name="common:base" /}

{block name="title"}注册 - 天佑二手货{/block}
{block name="page"}auth{/block}

{block name="header"}
<header>
    <div class="am-g">
        <h1>天佑二手货</h1>
        <p>TianYou Secondary Market
            <br/>交大人自己的二手市场！</p>
    </div>
    <hr />
</header>
{/block}

{block name="main"}
<div class="am-g am-g-fixed">
    <div class="am-u-sm-6 am-u-sm-centered">
        <h3>注册账户</h3>
        <hr>
        <h5>
            您可以 <a class="am-badge am-radius am-badge-primary" href="#">通过互联登陆直接注册 </a>
            <span class="am-icon-question-circle-o tips" data-am-popover="{theme: 'sm', content: '互联登陆是@！#￥……￥@%', trigger: 'hover focus'}"></span>
        </h5>
        <hr>
        <form class="am-form">
            <label for="email">邮箱:</label>
            <input type="email" name="email" id="email" value="">
            <br>
            <label for="username">用户名:</label>
            <input type="text" name="username" id="username" value="">
            <br>
            <label for="password">密码:</label>
            <input type="password" name="password" id="password" value="">
            <br>
            <label for="repassword">密码确认:</label>
            <input type="password" name="repassword" id="repassword" value="">
            <br />
            <div class="am-form-group am-form-icon am-form-feedback am-g-collapse am-cf">
                <label for="captcha" class="am-u-sm-3 am-form-label">
                    <div id="captcha-img" title="刷新验证码"><img src="{:captcha_src()}" alt="captcha" /></div>
                </label>
                <div class="am-u-sm-9">
                    <input type="text" name="captcha" id="captcha" class="am-form-field" placeholder="请输入验证码">
                    <!-- <span class="am-icon-warning"></span> -->
                </div>
            </div>
            <div class="am-cf">
                <input type="submit" name="" value="注册" class="am-btn am-btn-sm am-btn-primary">
                <a class="am-btn am-btn-sm am-fr am-btn-default" href="{:url('auth/login')}">登陆</a>
            </div>
        </form>
    </div>
</div>
{/block}

{block name="js"}
<script type="text/javascript">
    $('.am-form').submit(function(event) {
        event.preventDefault();
        $.ajax({
            url: "{:url('auth/register')}",
            type: 'POST',
            data: $('.am-form').serialize(),
            success: function(data) {
                $alert = $('#am-alert');
                $alert.find('.content').text(data.msg);
                $alert.modal('open');
                if(data.code) {
                    setTimeout(function() {
                        location.href = data.url;
                    }, data.wait*1000);
                } else {
                    $('#captcha-img').click();
                }
            }
        })
    });
</script>
{/block}
